"use strict";
const { Model } = require("sequelize");
module.exports = (sequelize, DataTypes) => {
  class Factory extends Model {
    /**
     * Helper method for defining associations.
     * This method is not a part of Sequelize lifecycle.
     * The `models/index` file will call this method automatically.
     */
    static associate(models) {
      // Factory.belongsTo(models.Contract,{
      //   foreignKey:'factory_id'
      // })// define association here
      Factory.hasMany(models.Product, {
        foreignKey: "factory_id",
        // onDelete: 'CASCADE',
        // onUpdate:'CASCADE'
      });
      // Factory.belongsTo(models.Staff,{
      //   foreignKey:'checker_id',
      //   as:'checker',
      //   unique: false
      // })
    }
  }
  Factory.init(
    {
      name: DataTypes.STRING,
      address: DataTypes.STRING,
      website: DataTypes.STRING,
      person_name: DataTypes.STRING,
      person_phone: {
        type: DataTypes.STRING,
        // unique:true
      },
      person_email: {
        type: DataTypes.STRING,
        // unique:true
      },
      person_position: DataTypes.STRING,
      check_status: {
        type: DataTypes.STRING,
        defaultValue: "待审核",
      },
      check_sug: DataTypes.STRING,
      factory_type: DataTypes.STRING,
      checker_id: DataTypes.INTEGER, //审核人id
    },
    {
      sequelize,
      modelName: "Factory",
      tableName: "factories",
    }
  );
  return Factory;
};
